package org.hawk.gwt.ppc.scanner;

import java.util.ListIterator;
/**
 * Represents chain of tokens to be processed.
 * You can iterate the token chain, commit it to the output or
 * skip some changes to become non-commitable.
 * @author alex.bereznevatiy@gmail.com
 */
public interface TokenChain<T extends Token> extends ListIterator<T> {
	/**
	 * Sends the current token and all preceded tokens to
	 * the output stream associated. The operation is valid 
	 * for tokens after last commit point. In case if you call 
	 * it for token that is already commit - it simply does nothing.
	 */
	void commit();
	/**
	 * Skips all the token after the last commit point till current
	 * iterator position. In case if you call it for token 
	 * that is already commit - it simply does nothing.
	 */
	void skip();
	/**
	 * Adds token using string presentation.
	 * @param token
	 */
	void add(String token);
	/** 
	 * @return reference to current element in the iterator.
	 */
	T current();
	/**
	 * @return index of current element
	 */
	int index();
	/**
	 * Moves iterator position to the index specified. If index is less than 
	 * zero or more than length of token chain {@link IndexOutOfBoundsException} 
	 * will occur.
	 * @param index
	 * @throws IndexOutOfBoundsException
	 */
	void moveTo(int index) throws IndexOutOfBoundsException;
}
